package org.jasig.cas.web.dao;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created by catold on 16/4/20.
 */
public class UserDao extends JdbcDaoSupport {
    public boolean insert(String userName, String password, String email, String credit) {
        String sql = "INSERT INTO USER " +
                "(USERNAME, PASSWORD, EMAIL, CREDIT) VALUES (?, ?, ?, ?)";

        Connection conn = null;
        boolean result = false;
        try {
            conn = this.getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, userName);
            ps.setString(2, password);
            ps.setString(3, email);
            ps.setString(4, credit);
            ps.executeUpdate();
            ps.close();
            result = true;
        } catch (SQLException e) {
            throw new RuntimeException(e);

        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }

        return result;
    }

}

